home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tex / textyl / textyl.shar4.Z / textyl.shar4
Encoding:
Text File  |  1987-08-10  |  64.4 KB  |  2,174 lines

  1. #!/bin/sh
  2. # to extract, remove the header and type "sh filename"
  3. if `test ! -d ./src`
  4. then
  5.   mkdir ./src
  6.   echo "mkdir ./src"
  7. fi
  8. if `test ! -s ./src/textyl.pas.ae`
  9. then
  10. echo "writing ./src/textyl.pas.ae"
  11. cat > ./src/textyl.pas.ae << 'E_O_F'
  12.    if (figdepth = 0) then 
  13.      begin      (* ---- do the primitive by itself *)
  14.       (* re-transform it to the 4th Quadrant *)
  15.      dvilinepts (x1, y1, x2, y2, h, v);  (* global h and v posit *)
  16.      IPUSH;
  17.      TylLine (x1, y1, x2, y2, thk, vk, patt);
  18.      IPOP;
  19.      end
  20.   else if (figdepth > 0) then
  21.      begin      (* ---- Pack it and stack it *)
  22.      lineitem := NewItem (Aline);
  23.      with lineitem^ do
  24.        begin
  25.        BBlx := minx;     BBby := miny;
  26.        BBrx := maxx;     BBty := maxy;
  27.        lx1 := x1;     ly1 := y1;
  28.        lx2 := x2;    ly2 := y2;
  29.        itemthick := thk;
  30.        itemvec := vk;
  31.        itempatt := patt;
  32.        end;  
  33.      pushItem (figdepth, lineitem);
  34.      end
  35.    else if (figdepth < 0) then
  36.      begin      (* ---- just do it right away without any PUSH/POP pair *)
  37.              (* this is the case when we are unpacking a figure for
  38.          *  immediate output
  39.          *)
  40.      TylLine (x1, y1, x2, y2, thk, vk, patt);
  41.      end;  
  42. end;  (*  linehandle *)
  43.  
  44.  
  45. (* ---   Simple Splines -----*)
  46. {-----------------------------------------------------}
  47. procedure splinehandle (figdepth : integer; scalefact : real;
  48.                         thetype : SplineKind; isclosed : boolean;
  49.             markdiam : integer;
  50.                         var contpts : ControlPoints;
  51.                         nknots : integer;
  52.                         dvih, dviv : ScaledPts; (* possible dvi-offsets *)
  53.                         thk : VThickness; vec : VectKind;
  54.             patt : LineStyle;
  55.                         minx, maxx, miny, maxy : ScaledPts;
  56.                         tx, ty : ScaledPts; sx, sy, r : real);
  57. var midx, midy : ScaledPts;                     
  58.     splineitem : pItem;
  59.     i : integer;
  60. begin
  61.    midx := (minx + maxx) div 2;
  62.    midy := (miny + maxy) div 2;
  63.    
  64.    xfmcontpts (contpts, nknots, dvih, dviv, midx, midy,
  65.                 scalefact, r, tx, ty, sx, sy);
  66.  
  67.    if (figdepth = 0) then
  68.      begin      (* ----  do the primitive *)
  69.      (* transform to 4th quad *)
  70.      dvicontpts (contpts, nknots, h, v);
  71.      IPUSH;
  72.      TylSpline (thetype, isclosed, contpts, nknots, thk, vec, patt, markdiam);
  73.      IPOP;
  74.      end
  75.    else if (figdepth > 0) then
  76.      begin
  77.      splineitem := NewItem (Aspline);
  78.      with splineitem^ do
  79.        begin
  80.        BBlx := minx; BBby := miny;
  81.        BBrx := maxx; BBty := maxy;
  82.        itemthick := thk;
  83.        itemvec := vec;
  84.        itempatt := patt;
  85.        nsplknots := nknots;
  86.        spltype := thetype;
  87.        sclosed := isclosed;
  88.        dosmarks := markdiam;
  89.        for i := 1 to nknots do
  90.          begin
  91.          spts[i,1] := contpts[i,1];
  92.          spts[i,2] := contpts[i,2];
  93.          end;
  94.        end;  
  95.      pushItem (figdepth, splineitem);
  96.      end
  97.    else if (figdepth < 0) then
  98.      begin
  99.      TylSpline (thetype, isclosed, contpts, nknots, thk, vec, patt, markdiam);
  100.      end;  
  101. end;  (*  splinehandle *)
  102.  
  103.  
  104. (* --- Variable thickness splines ----- *)
  105. {-----------------------------------------------------}
  106. procedure ttsplhandle (figdepth : integer; scalefact : real;
  107.                         thetype : SplineKind; isclosed : boolean;
  108.             markdiam : integer;
  109.                         contpts : ControlPoints;
  110.                         ttks : ThickAryType;
  111.                         nknots : integer; 
  112.                         dvih, dviv : ScaledPts; (* possible dvi-offsets *)
  113.                         vec : VectKind;
  114.             patt : LineStyle;
  115.                         minx, maxx, miny, maxy : ScaledPts;
  116.                         tx, ty : ScaledPts; sx, sy, r : real);
  117. var midx, midy : ScaledPts;
  118.     ttsplitem : pItem;
  119.     i : integer;
  120. begin
  121.    midx := (minx + maxx) div 2;
  122.    midy := (miny + maxy) div 2;
  123.    
  124.    xfmcontpts (contpts, nknots, dvih, dviv, midx, midy,
  125.                 scalefact, r, tx, ty, sx, sy);
  126.  
  127.    if (figdepth = 0) then
  128.      begin
  129.      (* transform to 4th quad      *)
  130.      dvicontpts (contpts, nknots, h, v);
  131.      IPUSH;
  132.      TylThickThinSpline (thetype, isclosed, contpts, ttks, nknots, vec, patt, markdiam);
  133.      IPOP;
  134.      end
  135.    else if (figdepth > 0) then
  136.      begin
  137.      ttsplitem := NewItem (Attspline);
  138.      with ttsplitem^ do
  139.        begin
  140.        BBlx := minx; BBby := miny;
  141.        BBrx := maxx; BBty := maxy;
  142.        itemvec := vec;
  143.        itempatt := patt;
  144.        nttknots := nknots;
  145.        tspltype := thetype;
  146.        dottmarks := markdiam;
  147.        tclosed := isclosed;
  148.        for i := 1 to nknots do
  149.          begin
  150.          ttpts[i,1] := contpts[i,1];
  151.          ttpts[i,2] := contpts[i,2];
  152.          ttarry[i] := ttks[i];
  153.          end;
  154.        end;  (*  ttsplitem *)
  155.      pushItem (figdepth, ttsplitem);
  156.      end
  157.    else if (figdepth < 0) then
  158.      begin
  159.      TylThickThinSpline (thetype, isclosed, contpts, ttks, nknots, vec, patt, markdiam);
  160.      end;  
  161.   
  162. end;  (*  ttsplhandle *)
  163.  
  164.  
  165. (* ---- Musical Beams ---- *)
  166. {-----------------------------------------------------}
  167. procedure beamhandle (depth, siz : integer; bk : BeamKind;
  168.                         x1, y1, x2, y2 : ScaledPts);
  169. var bmitem : pItem;
  170. begin
  171.     if (depth = 0) then
  172.       begin
  173.       dvilinepts (x1, y1, x2, y2, h, v);
  174.       IPUSH;
  175.       TylBeam (x1, y1, x2, y2, siz, bk);
  176.       IPOP;
  177.       end
  178.     else if (depth > 0) then
  179.       begin
  180.       bmitem := NewItem (Abeam);
  181.       with bmitem^ do
  182.         begin
  183.         BBlx := min(x1, x2);     BBby := min(y1, y2);
  184.         BBrx := max(x1, x2);     BBty := max(y1, y2);
  185.     bx1 := x1;        by1 := y1;
  186.     bx2 := x2;        by2 := y2;    
  187.         staf := siz;
  188.         bkind := bk;
  189.         end;  (* with *)
  190.       pushItem (depth, bmitem);
  191.       end
  192.     else if (depth < 0) then
  193.       begin
  194.       TylBeam (x1, y1, x2, y2, siz, bk);      
  195.       end;  (* else *)
  196. end;  (*  beamhandle *)
  197.  
  198.  
  199. (* ---- Musical Ties and Slurs ----- *)
  200. {-----------------------------------------------------}
  201. procedure tieslurhandle (depth: integer; pts : ControlPoints;
  202.                         numk : integer; minthick, maxthick : VThickness);
  203. var tsitem : pItem;
  204.     i : integer;
  205. begin
  206. if (depth = 0) then
  207.    begin
  208.      dvicontpts (pts, numk, h, v);
  209.      IPUSH;
  210.      TylTieSlur (pts, numk, minthick, maxthick);
  211.      IPOP;
  212.    end
  213. else if (depth > 0) then
  214.  begin
  215.   tsitem := NewItem (Atieslur);
  216.   with tsitem^ do
  217.     begin
  218.     ntknots := numk;
  219.     for i := 1 to numk do 
  220.       begin
  221.       tspts[i,1] := pts[i,1];
  222.       tspts[i,2] := pts[i,2];
  223.       end;
  224.     minth := minthick;
  225.     maxth := maxthick;
  226.     end;  (* with *)
  227.   pushItem (depth, tsitem);
  228.   end
  229. else if (depth < 0) then
  230.   begin
  231.   TylTieSlur (pts, numk, minthick, maxthick);      
  232.   end;  (* else *)
  233. end;  (*  tieslurhandle *)
  234.  
  235.  
  236. {---------------------------------------------------------}
  237. procedure arccirclehandle (figdepth : integer; scalefact : real;
  238.             cx, cy : ScaledPts;
  239.             radius : ScaledPts;
  240.             ang1, ang2 : integer;
  241.             var contpts : ControlPoints; (* IN *)
  242.             nknots : integer;
  243.             dvih, dviv : ScaledPts; (* possible dvi-offsets *)
  244.             thk : VThickness; vec : VectKind;
  245.             patt : LineStyle;
  246.             minx, maxx, miny, maxy : ScaledPts;
  247.             tx, ty : ScaledPts; sx, sy, r : real);
  248.  
  249. var midx, midy : ScaledPts;                     
  250.     middlex, middley : ScaledPts;
  251.     arcitem : pItem;
  252.     i : integer;
  253.     isclosedarc : boolean;
  254.  
  255. begin
  256.    midx := cx;  middlex := (minx + maxx) div 2;
  257.    midy := cy;    middley := (miny + maxy) div 2;
  258.    isclosedarc := (ang1 = ang2);
  259. {
  260.    if (isclosedarc) then
  261.      maxspanlen := round ((360.0 / 16.0) * DEGTORAD * radius)
  262.    else
  263.      maxspanlen := round ((abs(ang2 - ang1) / 16.0) * DEGTORAD * radius);
  264. { }
  265.  
  266.  
  267.    xfmcontpts (contpts, nknots+1, dvih, dviv, midx, midy,
  268.                 scalefact, r, tx, ty, sx, sy);
  269.  
  270.    if (figdepth = 0) then
  271.      begin      (* ---- just do the primitive *)
  272.      (* transform to 4th quad *)
  273.      dvicontpts (contpts, nknots+1, h, v);
  274.      IPUSH;
  275.      doTylArc (isclosedarc, 
  276.              contpts, nknots, thk, vec, patt); 
  277.      IPOP;
  278.      end
  279.    else if (figdepth > 0) then
  280.      begin
  281.      arcitem := NewItem (Aarc);
  282.      with arcitem^ do
  283.        begin
  284.        BBlx := minx; BBby := miny;
  285.        BBrx := maxx; BBty := maxy;
  286.        itemthick := thk;
  287.        itemvec := vec;
  288.        itempatt := patt;
  289.        narcknots := nknots;
  290.        acentx := cx;
  291.        acenty := cy;
  292.        aradius := radius;
  293.        firstang := ang1;
  294.        lastang := ang2;
  295.        for i := 0 to nknots+1 do
  296.          begin
  297.          arcpts[i,1] := contpts[i,1];
  298.          arcpts[i,2] := contpts[i,2];
  299.          end;
  300.        end;  
  301.      pushItem (figdepth, arcitem);
  302.      end
  303.    else if (figdepth < 0) then
  304.      begin
  305.      doTylArc (isclosedarc, contpts, nknots, thk, vec, patt);
  306.      end;  
  307. end;  (*  arccirclehandle *)
  308.  
  309.  
  310.  
  311. {---------------------------------------------------------}
  312. procedure labelhandle (depth : integer; scalefact: real; 
  313.                        lax, lay : ScaledPts;
  314.                        dvih, dviv : ScaledPts; (* possible dvi-offsets *)
  315.                style : integer; 
  316.                phrase : strng;
  317.                tx, ty : ScaledPts);
  318. var labitem : pItem;
  319.     null1, null2 : ScaledPts;
  320. begin
  321. (* xfm the label point if necessary *)
  322.   lax := lax + round(tx * scalefact);
  323.   lay := lay + round(ty * scalefact);
  324.  
  325.   if (depth = 0) then
  326.     begin
  327.     null1 := 0; null2 := 0;
  328.     dvilinepts (lax, lay, null1, null2, h, v);
  329.     IPUSH;
  330.     TylLabel (lax, lay, style, phrase.str, phrase.len);
  331.     IPOP;
  332.     end
  333.   else if (depth > 0) then
  334.     begin
  335.     labitem := NewItem (Alabel);
  336.     with labitem^ do
  337.       begin
  338.       labx := lax; 
  339.       laby := lay;
  340.       fontstyle := style;
  341.       strcopy (phrase.str, labeltext.str, phrase.len);
  342.       labeltext.len := phrase.len;
  343.       end;  
  344.     pushItem (depth, labitem);
  345.     end  
  346.   else if (depth < 0) then
  347.     begin
  348.     TylLabel (lax, lay, style, phrase.str, phrase.len);
  349.     end; 
  350. end;
  351.  
  352.  
  353. (* ####   Insert new handlers here for new "primitives"
  354.     i.e., names callable from the \special[tyl ...]  level 
  355. *)
  356.  
  357.  
  358.  
  359. {----------------------------------------------------------------}
  360. (*  transform the current bbox coordinates, and output the new one *)
  361. procedure newbbox (var minx, maxx, miny, maxy : ScaledPts;
  362.                    midx, midy : ScaledPts;
  363.                    sx, sy, rot : real; tx, ty : ScaledPts);
  364. var
  365.       (* coords of full bbox for transformation [n/s][e/w][x/y] *)
  366.    nex, ney, sex, sey, swx, swy, nwx, nwy: ScaledPts; 
  367.    temp1, temp2 : integer;
  368. begin
  369.   (* describe  and transform the bbox *)
  370.   nwx := round (minx * sx);      nex := round (maxx * sx);
  371.   sex := round (maxx * sx);      swx := round (minx * sx);
  372.   ney := round (maxy * sy);      nwy := round (maxy * sy);
  373.   swy := round (miny * sy);      sey := round (miny * sy);
  374.   
  375.   ptrotate (nex, ney, midx, midy, rot);
  376.   ptrotate (sex, sey, midx, midy, rot);
  377.   ptrotate (swx, swy, midx, midy, rot);
  378.   ptrotate (nwx, nwy, midx, midy, rot);
  379.   
  380.   nex := nex + tx; sex := sex + tx;
  381.   swx := swx + tx; nwx := nwx + tx;
  382.   ney := ney + ty; sey := sey + ty;
  383.   swy := swy + ty; nwy := nwy + ty;
  384.   (* now find the actual extents of the bbox *)
  385.   temp1 := min (nex, nwx);
  386.   temp2 := min (swx, sex);
  387.   minx := min (temp1, temp2);
  388.   
  389.   temp1 := min (ney, nwy);
  390.   temp2 := min (swy, sey);
  391.   miny := min (temp1, temp2);
  392.     
  393.   temp1 := max (nex, nwx);
  394.   temp2 := max (swx, sex);
  395.   maxx := max (temp1, temp2);
  396.   
  397.   temp1 := max (ney, nwy);
  398.   temp2 := max (swy, sey);
  399.   maxy := max (temp1, temp2);      
  400. end;
  401.       
  402.      
  403. {-----------------------------------------------}
  404. (* find the bounding box of the list of primitives  
  405.     and/or sub-figures in this Item *)
  406.  
  407. procedure findBBox (blot : pItem; 
  408.                 var mnx, mxx, mny, mxy : ScaledPts);
  409. var 
  410.    pi : pItem;
  411.    bmnx, bmxx, bmny, bmxy, midx, midy : ScaledPts; (* bbox [min/max][x/y] *)
  412.    tmnx, tmxx, tmny, tmxy : ScaledPts;  (* temporary, in case of recursion *)
  413.    null1, null2 : ScaledPts;
  414.    prescale, postscale : real;
  415.    old1, old2 : ScaledPts;
  416. begin
  417.   bmnx := TWO24; bmny := TWO24;
  418.   bmxx := -TWO24; bmxy :=-TWO24;
  419.   if (blot^.kind = Afigure) then
  420.     begin (* afigure *)
  421.     pi := blot^.body^.things;
  422.     while (pi <> nil) do
  423.       begin (* find the current bbox of the list of items here *)
  424.       if (pi^.kind = Afigure) then
  425.         begin  (* recur *)
  426.         findBBox (pi, tmnx, tmxx, tmny, tmxy);
  427.         bmnx := min (bmnx, tmnx);
  428.         bmny := min (bmny, tmny);
  429.         bmxx := max (bmxx, tmxx);
  430.         bmxy := max (bmxy, tmxy);
  431.         end
  432.       else
  433.         begin
  434.         bmnx := min (bmnx, pi^.BBlx);
  435.         bmny := min (bmny, pi^.BBby);
  436.         bmxx := max (bmxx, pi^.BBrx);
  437.         bmxy := max (bmxy, pi^.BBty);
  438.         end;
  439.       pi := pi^.nextitem;
  440.       end;  (* while *)
  441.         (* now transform the items inside, AND the bbox *)
  442.     pi := blot^.body^.things;
  443.     midx := (bmnx + bmxx) div 2;
  444.     midy := (bmny + bmxy) div 2;
  445.     (* now take care of any pre and post size requirements *)
  446.     (* see also the "figurehandle" proc. *)
  447.      with blot^ do
  448.       begin  
  449. (* ### Keep this scaling biz here, too, for now. May blast it later *)
  450.       if ((preWid <> 0) and (preHt <> 0)) then
  451.     begin
  452.     prescale := scalefitfactor ((bmxx - bmnx), (bmxy - bmny), preWid, preHt);
  453.     fsx := fsx * prescale;
  454.     fsy := fsy * prescale;
  455.     end;
  456.       if ((postWid <> 0) and (postHt <> 0)) then
  457.     begin
  458.     postscale := scalefitfactor ((bmxx - bmnx), (bmxy - bmny), postWid, postHt);
  459.     fsx := fsx * postscale;
  460.     fsy := fsy * postscale;
  461.     end;
  462.  
  463. (* the actual scale-up is taken care of later in this proc. *)
  464.       end; (* with *)  
  465.     while (pi <> nil) do
  466.       begin
  467.       with pi^ do
  468.         begin
  469.         case (kind) of
  470.           Aline : begin
  471.                   xfmlinepts (lx1, ly1, lx2, ly2, 0, 0, midx, midy, 1.0, 
  472.                         blot^.figtheta, blot^.fdx, blot^.fdy,
  473.                         blot^.fsx, blot^.fsy);
  474.                   end;
  475.           Aspline : begin
  476.                     xfmcontpts (spts, nsplknots, 0, 0, midx, midy, 1.0,
  477.                         blot^.figtheta, blot^.fdx, blot^.fdy,
  478.                         blot^.fsx, blot^.fsy);
  479.                     end;
  480.           Attspline : begin
  481.                       xfmcontpts (ttpts, nttknots, 0, 0, midx, midy, 1.0,
  482.                         blot^.figtheta, blot^.fdx, blot^.fdy,
  483.                         blot^.fsx, blot^.fsy);
  484.                       end;
  485.       Aarc : begin
  486.          null1 := 0; null2 := 0;
  487.          old1 := acentx; old2 := acenty;
  488.            xfmlinepts (acentx, acenty, null1, null2, 0,0, midx, midy, 1.0,
  489.                         blot^.figtheta, blot^.fdx, blot^.fdy,
  490.                         blot^.fsx, blot^.fsy);
  491.            xfmcontpts (arcpts, narcknots + 1, 0, 0, old1, old2, 1.0,
  492.                         blot^.figtheta, 
  493.             blot^.fdx + (acentx - old1),
  494.             blot^.fdy + (acenty - old2),
  495.                         blot^.fsx, blot^.fsy);
  496.                  end;              
  497.       Alabel : begin
  498.            null1 := 0; null2 := 0;
  499.              xfmlinepts (labx, laby, null1, null2, 0,0, midx, midy, 1.0,
  500.                         blot^.figtheta, blot^.fdx, blot^.fdy,
  501.                         blot^.fsx, blot^.fsy);        
  502.            end;
  503.           Abeam : ;   (* not transformable *)
  504.  
  505.           Atieslur: ; (* not transformable *)
  506.           Afigure : ; (* do not need to re-transform *)
  507.         end; (* case *)
  508.       end; (* with *)
  509.       pi := pi^.nextitem;
  510.       end;  (* while *)
  511.     (* transform the bbox, and re-find the new bbox *)
  512.     newbbox (bmnx, bmxx, bmny, bmxy, midx, midy, blot^.fsx, blot^.fsy,
  513.                 blot^.figtheta, blot^.fdx, blot^.fdy);
  514.     mnx := bmnx; mny := bmny;
  515.     mxx := bmxx; mxy := bmxy;
  516.     end  (* if *)
  517.   else (* some other primitive *)
  518.     begin
  519.     mnx := blot^.BBlx; mny := blot^.BBby;
  520.     mxx := blot^.BBrx; mxy := blot^.BBty;
  521.     end;  (* else *)
  522. end;  (*  findBBox *)
  523.  
  524.  
  525. {---------------------------------------------------------}
  526. (* traverse the list, determining the current bounding box for
  527.  *       the items. We need this to find the mid-point
  528.  *       for doing any remaining rotations 
  529.  *)
  530. procedure traverse (thefig, theitem : pItem);
  531. var 
  532.     minx, maxx, miny, maxy : ScaledPts;  
  533.     curminx, curmaxx, curminy, curmaxy : ScaledPts;  
  534. begin
  535.   minx := TWO24; maxx := -TWO24;
  536.   miny := TWO24; maxy := -TWO24;
  537.   
  538.   while (theitem <> nil) do
  539.     begin
  540.     if (theitem^.kind = Afigure) then
  541.       begin (* recur *)
  542.       findBBox (theitem, curminx, curmaxx, curminy, curmaxy);
  543.       with theitem^ do
  544.         begin
  545.         BBlx := curminx;         BBby := curminy;
  546.         BBrx := curmaxx;         BBty := curmaxy;
  547.            (* reset the symbol's parameters since all the
  548.                 primitives in it have now been transformed
  549.                 according to the previous specifications *)
  550.         figtheta := 0.0; 
  551.         fsx := 1.0;      fsy := 1.0;
  552.         fdx := 0;        fdy := 0;
  553.     preWid := 0;     preHt := 0;
  554.     postWid := 0;     postHt := 0;
  555.         end;  (* with *)
  556.       minx := min (minx, curminx);      miny := min (miny, curminy);
  557.       maxx := max (maxx, curmaxx);      maxy := max (maxy, curmaxy);
  558.       end  (* if a figure/symbol*)
  559.     else
  560.       begin  (* a primitive *)
  561.       with theitem^ do 
  562.         begin
  563.         minx := min (minx, BBlx);        miny := min (miny, BBby);
  564.         maxx := max (maxx, BBrx);        maxy := max (maxy, BBty);
  565.         end;  (* with *)
  566.       end;  (* else *)
  567.     theitem := theitem^.nextitem;
  568.     end;  (* while *)
  569.  
  570.   with thefig^ do
  571.     begin  (* set the bounding box for this upper-level symbol defn *)
  572.     BBlx := minx;
  573.     BBby := miny;
  574.     BBrx := maxx;
  575.     BBty := maxy;
  576.     end;  (* with *)
  577. end;  (* traverse *)
  578.  
  579. (* ----- Figure symbols ----- *)
  580. {---------------------------------------------------}
  581. procedure figurehandle (globalsymlist, symbollist : pItem; dopush : integer);
  582. const DoItNow = -1;
  583.       NoScale = 1;
  584. var pi, curfig : pItem;
  585.     midx, midy : ScaledPts;
  586.     null1, null2 : ScaledPts;
  587.     prescale, postscale : real;
  588.     tmnx, tmny, tmxx, tmxy : ScaledPts;
  589. begin (* figurehandle *)
  590.  
  591.     (* PUSH. traverse the lists (recursively if necessary) and 
  592.      * compute the transformed points.
  593.      * Convert to 4th quadrant and offset by H & V.
  594.      * We can do this destructively here
  595.      * since we're going to output them right away anyhow.
  596.      * Then call each respective primitive handler with a level
  597.      * of -1 to indicate  to do its job immediately. 
  598.      * POP.     
  599.      *)
  600.   curfig := symbollist;
  601.   pi := curfig^.body^.things;
  602.         (* find and set the bounding box for
  603.          the figure's sub-symbols and primitives *)
  604.   if (dopush > 0) then
  605.     traverse (curfig, pi); 
  606.   
  607.       (* We eventually transform the items
  608.      to 4th Quadrant DVI space and output them! *)
  609.  
  610.   pi := curfig^.body^.things;
  611.  
  612.   midy := (globalsymlist^.BBby + globalsymlist^.BBty) div 2;
  613.   midx := (globalsymlist^.BBlx + globalsymlist^.BBrx) div 2;
  614.  
  615.   if (dopush > 0) then 
  616.     begin (* the top-level figure for outputting *)
  617.  
  618.     (* convert the bounding box because we are about to enter
  619.         into DVI space, and all calls to handlers hereafter
  620.     are in terms of DVI coordinates *)
  621.  
  622.       with globalsymlist^ do
  623.         begin 
  624.  
  625. (* Since there were external specifications about this figure,
  626.     fit the current figure's actual size to the 
  627.     "pre" size (specified by W marker) and/or to the
  628.     "post" size (specified by the F marker). 
  629.     We do this by simple scaling, *without* changing the midpoint
  630.     of the bounding box, just its extents
  631.  *)
  632.     if ((preWid <> 0) and (preHt <> 0)) then
  633.       begin
  634.       prescale := scalefitfactor ((BBrx - BBlx), (BBty - BBby), preWid, preHt);
  635.       fsx := fsx * prescale;
  636.       fsy := fsy * prescale;
  637.       end;
  638.     if ((postWid <> 0) and (postHt <> 0)) then
  639.       begin
  640.       postscale := scalefitfactor ((BBrx - BBlx), (BBty - BBby), postWid, postHt);
  641.       fsx := fsx * postscale;
  642.       fsy := fsy * postscale;
  643.       end;
  644.     tmnx := BBlx; tmny := BBby; tmxx := BBrx; tmxy := BBty;
  645.     xfmlinepts (tmnx, tmny, tmxx, tmxy, 0,0, midx, midy, 1.0,
  646.             0.0, 0, 0, fsx, fsy);
  647.  
  648.     toplevelxfm (globalsymlist, globalsymlist, 0);
  649.     
  650.     dviBBlx := tmnx; 
  651.     dviBBrx := tmxx; 
  652.     dviBBby := tmny;
  653.     dviBBty := tmxy;
  654.  
  655.     xfmlinepts (dviBBlx, dviBBby, dviBBrx, dviBBty, 0,0,
  656.         midx, midy, 1.0, 0.0,
  657.         - (tmnx - BBlx), - (tmny - BBby),
  658.         1.0, 1.0);
  659.  
  660.     fdx := fdx - (tmnx - BBlx);
  661.     fdy := fdy - (tmny - BBby);
  662.     end;
  663.  
  664.       dvilinepts (dviBBlx, dviBBby, dviBBrx, dviBBty, h, v);
  665.       pgfigurenum := pgfigurenum + 1;
  666.  
  667.     (* We are ready to output the figure to the page *)
  668.       writeln(logfile);
  669.       write(logfile,'Figure #',pgfigurenum:0,' on page ',currpagenum:0,' is approx. ');
  670. {      write(logfile,((globalsymlist^.BBty - globalsymlist^.BBby) div SPPERPT):0,' pts high and ');
  671.       writeln(logfile,((globalsymlist^.BBrx - globalsymlist^.BBlx) div SPPERPT):0,' pts wide (actual size)');
  672. }
  673.     write(logfile,((tmxy - tmny) div SPPERPT):0,' pts high and ');
  674.     writeln(logfile,((tmxx - tmnx) div SPPERPT):0,' pts wide (actual size)');
  675.       IPUSH;  
  676.  
  677.     end;
  678.  
  679.   while (pi <> nil) do
  680.     begin
  681.     with pi^ do
  682.         begin
  683.         case (kind) of
  684.           Aline : begin
  685.                  dvilinepts (lx1, ly1, lx2, ly2, h, v); (* DVI h and v posit *)
  686.                  with globalsymlist^ do
  687.                  linehandle (DoItNow, NoScale, 
  688.                                 pi^.lx1, pi^.ly1, pi^.lx2, pi^.ly2,
  689.                                 0, 0,  
  690.                                 pi^.itemthick, pi^.itemvec, pi^.itempatt,
  691.                 dviBBlx, dviBBrx, dviBBby, dviBBty,
  692.                                 fdx, -fdy, fsx, fsy, -figtheta);
  693.                  end; (* Aline *)
  694.          
  695.          Aspline : begin
  696.                    dvicontpts (spts, nsplknots, h, v);
  697.                    with globalsymlist^ do
  698.                    splinehandle (DoItNow, NoScale, pi^.spltype, 
  699.                    pi^.sclosed, pi^.dosmarks,
  700.                                 pi^.spts, pi^.nsplknots,
  701.                                 0, 0,
  702.                                 pi^.itemthick, pi^.itemvec, pi^.itempatt,
  703.                                 dviBBlx, dviBBrx, dviBBby, dviBBty,
  704.                                 fdx, -fdy, fsx, fsy, -figtheta);
  705.                   end; (* Aspline *)
  706.          
  707.           Attspline : begin
  708.                    dvicontpts (ttpts, nttknots, h, v);
  709.                    with globalsymlist^ do
  710.                    ttsplhandle (DoItNow, NoScale, pi^.tspltype, 
  711.                    pi^.tclosed, pi^.dottmarks,
  712.                                 pi^.ttpts, pi^.ttarry, pi^.nttknots,
  713.                                 0, 0,
  714.                                 pi^.itemvec, pi^.itempatt,
  715.                                 dviBBlx, dviBBrx, dviBBby, dviBBty,
  716.                                 fdx, -fdy, fsx, fsy, -figtheta);
  717.                   end; (* Attspline *)
  718.  
  719.           Abeam : begin 
  720.                   dvilinepts (bx1, by1, bx2, by2, h, v);
  721.                   beamhandle (DoItNow, staf, bkind, bx1, by1, bx2, by2);
  722.                   end; (* Abeam *)
  723.  
  724.           Atieslur : begin
  725.                      dvicontpts (tspts, ntknots, h, v);
  726.                      tieslurhandle (DoItNow, tspts, ntknots, minth, maxth);
  727.                      end;  (* a tie or slur *)
  728.  
  729.       Aarc : begin
  730.                    dvicontpts (arcpts, narcknots + 1, h, v);
  731.                    with globalsymlist^ do
  732.                    arccirclehandle (DoItNow, NoScale,
  733.                 pi^.acentx, pi^.acenty,
  734.                 pi^.aradius,
  735.                 pi^.firstang, pi^.lastang,
  736.                 pi^.arcpts, pi^.narcknots,
  737.                 0, 0,
  738.                 pi^.itemthick, pi^.itemvec, pi^.itempatt,
  739.                                 dviBBlx, dviBBrx, dviBBby, dviBBty,
  740.                 fdx, -fdy, fsx, fsy, -figtheta);
  741.            end; (* arc *)
  742.       Alabel : begin
  743.              null1 := 0; null2 := 0;
  744.              dvilinepts (labx, laby, null1, null2, h, v);
  745.            with globalsymlist^ do
  746.            labelhandle (DoItNow, NoScale,
  747.                    pi^.labx, pi^.laby, 
  748.                 0, 0,
  749.                 pi^.fontstyle, pi^.labeltext,
  750.                 fdx, -fdy);
  751.           end; (* label *)
  752.  
  753.           Afigure : begin (* recur *)
  754.                     figurehandle (globalsymlist, pi, 0);
  755.                     end; (* another symbol *)
  756.  
  757.         end; (* case *)
  758.       end; (* with *)
  759.     pi := pi^.nextitem;
  760.     end; (* while *)
  761.   if (dopush > 0) then 
  762.     begin
  763.     IPOP;
  764.     end;
  765. end;  (*  figurehandle *)
  766.  
  767.  
  768.  
  769. (* %%% *)
  770. {-----------------------------------------------------}
  771. procedure mainhandlespecials (specnum, numpbytes : integer);
  772. (* specnum is the DVI-number of the special
  773.  * numpbytes is the number of parameter bytes
  774.  *)
  775. label 888;
  776. const PARSLEN = 50;  (* Length of the byte-string-cache *)
  777.       EMPTY = 0;
  778. type charset = set of char;
  779. var siz, numknots : integer;  (* Lots of temp vars that we use *)
  780.      x1, y1, x2, y2 : integer;
  781.      sx100, sy100 : real;
  782.      transx, transy : ScaledPts;
  783.      rot : real;
  784.      SPscale : real;
  785.      cpts : ControlPoints;
  786.      thk : VThickness;
  787.      patt : LineStyle;
  788.      TTary : ThickAryType;
  789.      vk : VectKind;
  790.      bk : BeamKind;
  791.      markdiam : integer;
  792.      radius, ang1, ang2 : integer;
  793.      phrase : strng;
  794.      style : integer;
  795.      nam : strng;
  796.      sysnam : strng;    (* the first parameter of the \special *)
  797.      let : char;
  798.      i, gotten : integer;
  799.      b : OctByt;
  800.      pi : pItem;
  801.      minx, miny, maxx, maxy : ScaledPts;
  802.      maxthk, minthk : integer;
  803.  
  804.      tylnam,
  805.      beginfigurenam,    (* names used for string to string comparisons *)
  806.      endfigurenam,
  807.      linenam,
  808.      splinenam,
  809.      ttsplnam,
  810.      beamnam,
  811.      tieslurnam,
  812.      arcnam,
  813.      labelnam,
  814.      paramnam {internal} : charstring;
  815.  
  816.      splinetype : SplineKind;
  817.      isclosedspline : boolean;
  818.  
  819.      parsearray : array [1..PARSLEN] of OctByt; (* cache of bytes to run through *)
  820.      parsposit, parsmax : integer; (* current and max position in cache *)
  821.      usingstream : boolean;    (* whether we read/parse using cache or from file *)
  822.  
  823.  
  824. (*--------------------------------------------------------------
  825.       These procedures depend on the correct ordering of
  826.       GETs with respect to the number of bytes read in so far.
  827.       precond: byte "b" has been read and gotten < numpbytes
  828.       postcond: byte "b" has been read iff gotten < numpbytes.
  829.       If your impl. definition of READ is non-standard, you will
  830.       have to dink with the ordering and be really careful of
  831.       keeping track of 'gotten' and 'numpbytes' variables 
  832. --------------------------------------------------------------*)      
  833.  
  834.         function nextpbyte : integer;
  835.         begin
  836.           if (usingstream) then
  837.             begin
  838.             if (gotten < numpbytes) then
  839.               begin
  840.               nextpbyte := Dget1byte; 
  841.               gotten := gotten + 1;
  842.               end
  843.             else
  844.               nextpbyte := EMPTY;
  845.             end
  846.           else
  847.             begin (* not using stream *)
  848.             if (parsposit <= parsmax) then
  849.               begin
  850.               nextpbyte := parsearray[parsposit];
  851.               parsposit := parsposit + 1;
  852.               end
  853.             else
  854.               begin     (* at end of parse array, so read from stream now *)
  855.               usingstream := true;
  856.               if (gotten < numpbytes) then
  857.                 begin
  858.                 nextpbyte := Dget1byte;
  859.                 gotten := gotten + 1;
  860.                 end
  861.               else
  862.                 nextpbyte := EMPTY;
  863.               end;
  864.             end;  (* else *)
  865.         end;        
  866.         
  867. (* !!!!! Make sure all these predicates jive correctly with
  868.     the key-letter definitions          *) 
  869. {__________________________________________________________________}
  870.         function isanumber (b : integer) : boolean;
  871.         begin
  872.           isanumber :=  ((b >= xord['0']) and (b <= xord['9']));
  873.         end;
  874.         
  875.         function isaletter (b : integer) : boolean;
  876.         begin
  877.           isaletter := (((b >= xord['A']) and (b <= xord['Z'])) or
  878.                         ((b >= xord['a']) and (b <= xord['z'])) or
  879.              (b = xord['@']) or
  880.              (b = xord['"']) );
  881.         end;
  882.         
  883.         function isaspace (b : integer) : boolean;
  884.         begin
  885.           isaspace := ((b = xord[' ']) or 
  886.                  (b = CR) or
  887.                (b = LF) or
  888.                (b = HT) or
  889.                (b = FF));
  890.         end;
  891.         
  892.         function isdelimiter (b : integer) : boolean;
  893.         begin
  894.           (* not a key-letter *)
  895.           isdelimiter := (((b < xord['A']) or (b > xord['Z'])) and
  896.                          ((b < xord['a']) or (b > xord['z'])) and
  897.              (b <> xord['@']) and
  898.              (b <> xord['"']) );
  899.         end;
  900.       
  901.         function isnotnull (b : integer) : boolean;
  902.         begin
  903.           isnotnull := (b <> EMPTY);
  904.         end;
  905.         
  906.         
  907. {__________________________________________________________________}
  908.         function getnumber : integer;
  909.         var n : integer;
  910.             isneg : boolean;
  911.         begin
  912.           n := 0;
  913.           isneg := false;
  914.           while (  (isnotnull (b)) and
  915.                   (not (isanumber (b)))) do
  916.             begin       (* not a numeral *)
  917.             if (b = xord['-']) then
  918.               isneg := true;
  919.             b := nextpbyte;
  920.             end;
  921.     
  922.       while (isaspace (b)) do  (* Skip spaces *)
  923.         b := nextpbyte;
  924.  
  925.           while ( (isnotnull (b)) and
  926.                  isanumber (b)) do
  927.             begin (* a numeral *)
  928.             n := n * 10 + (b - xord['0']);
  929.             b := nextpbyte;
  930.             end;
  931.  
  932.           if ((gotten = numpbytes)  and
  933.                  isanumber (b)) then
  934.             begin  (* end condition *)
  935.             n := n * 10 + (b - xord['0']);
  936.             end; 
  937.  
  938.           if (isneg) then
  939.             getnumber := -(n)
  940.           else
  941.             getnumber := n;
  942.         end;
  943. {__________________________________________________________________}
  944.  
  945.         function getletter : char;
  946.         var k : char;
  947.         begin
  948.           k := ' ';
  949.           while ( (isnotnull (b)) and
  950.                    (isdelimiter (b) and not (isaspace (b)))) do
  951.             begin (* non letter *)
  952.             b := nextpbyte;
  953.             end;
  954.  
  955.          if  ( (isnotnull (b)) and
  956.                 ( isaletter (b) or isaspace (b)
  957.                  and not (isanumber (b)))) then
  958.           begin
  959.             k := xchr[b];
  960.             b := nextpbyte;
  961.           end;
  962.         getletter := k;
  963.         end;
  964. {__________________________________________________________________}
  965.  
  966.         function getanything : char;
  967.         var k : char;
  968.         begin
  969.           k := ' ';
  970.           while (not (isnotnull (b))) do
  971.             begin (* not usable *)
  972.             b := nextpbyte;
  973.             end;
  974.  
  975.          if (isnotnull (b)) then
  976.           begin
  977.             k := xchr[b];
  978.             b := nextpbyte;
  979.           end;
  980.         getanything := k;
  981.         end;
  982.  
  983. {****************************************************
  984.    The following routines look for key - letter tokens
  985.   that indicate certain attributes for a primitive.
  986.  
  987. Currently, the letters used are:
  988.     S    for scaled-points measurement
  989.     P    for printers points
  990.     M    millimeters measurement
  991.     C    use a Circular vector for drawing
  992.     H    Horizontal-pen vector
  993.     V    Vertical vector
  994.     B    B-spline
  995.     I    Interpolating B-spline
  996.     K    Catmull-Rom spline
  997.     D    Cardinal spline
  998.     U    Open spline
  999.     O    closed spline
  1000.     X    put marks on spline control pts
  1001.     T    Transformation marker
  1002.     R    Regular beam characters
  1003.     G    Grace Beam characters
  1004.     @    Specify center-point for arc/circle
  1005.     L    Line-style 
  1006.     F    for beginfigure: Fit figure to wid/ht
  1007.     W    for beginfigure: figure was created at this wid & ht
  1008. **************************************************}
  1009.  
  1010.  
  1011. {__________________________________________________________________}
  1012. E_O_F
  1013. else
  1014.   echo "will not over write ./src/textyl.pas.ae"
  1015. fi
  1016. chmod 644 ./src/textyl.pas.ae
  1017. if [ `wc -c ./src/textyl.pas.ae | awk '{printf $1}'` -ne 30998 ]
  1018. then
  1019. echo `wc -c ./src/textyl.pas.ae | awk '{print "Got " $1 ", Expected " 30998}'`
  1020. fi
  1021. if `test ! -s ./src/h00vars.h`
  1022. then
  1023. echo "writing ./src/h00vars.h"
  1024. cat > ./src/h00vars.h << 'E_O_F'
  1025. /* Copyright (c) 1979 Regents of the University of California */
  1026.  
  1027. /* static char sccsid[] = "@(#)vars.h 1.12 1/22/83"; */
  1028.  
  1029. #include <stdio.h>
  1030.  
  1031. /*
  1032.  * px - Berkeley Pascal interpreter
  1033.  *
  1034.  * Version 4.0, January 1981
  1035.  *
  1036.  * Original version by Ken Thompson
  1037.  *
  1038.  * Substantial revisions by Bill Joy and Chuck Haley
  1039.  * November-December 1976
  1040.  *
  1041.  * Rewritten for VAX 11/780 by Kirk McKusick
  1042.  * Fall 1978
  1043.  *
  1044.  * Rewritten in ``C'' using libpc by Kirk McKusick
  1045.  * Winter 1981
  1046.  *
  1047.  * Px is described in detail in the "PX 4.0 Implementation Notes"
  1048.  * The source code for px is in several major pieces:
  1049.  *
  1050.  *    int.c        C main program which reads in interpreter code
  1051.  *    interp.c    Driver including main interpreter loop and
  1052.  *            the interpreter instructions grouped by their
  1053.  *            positions in the interpreter table.
  1054.  *    utilities.c    Interpreter exit, backtrace, and runtime statistics.
  1055.  *
  1056.  * In addition there are several headers defining mappings for panic
  1057.  * names into codes, and a definition of the interpreter transfer
  1058.  * table. These are made by the script make.ed1 in this directory and 
  1059.  * the routine opc.c from ${PASCALDIR}. (see the makefile for details)
  1060.  */
  1061. #define PXPFILE        "pmon.out"
  1062. #define    BITSPERBYTE    8
  1063. #define    BITSPERLONG    (BITSPERBYTE * sizeof(long))
  1064. #define HZ        100
  1065. #define NAMSIZ        76
  1066. #define MAXFILES    32
  1067. #define PREDEF        2
  1068. #ifdef ADDR32
  1069. #define STDLVL        ((struct iorec *)(0x7ffffff1))
  1070. #define GLVL        ((struct iorec *)(0x7ffffff0))
  1071. #endif ADDR32
  1072. #ifdef ADDR16
  1073. #define STDLVL        ((struct iorec *)(0xfff1))
  1074. #define GLVL        ((struct iorec *)(0xfff0))
  1075. #endif ADDR16
  1076. #define FILNIL        ((struct iorec *)(0))
  1077. #define INPUT        ((struct iorec *)(&input))
  1078. #define OUTPUT        ((struct iorec *)(&output))
  1079. #define ERR        ((struct iorec *)(&_err))
  1080. #define    PX    0    /* normal run of px */
  1081. #define    PIX    1    /* load and go */
  1082. #define    PIPE    2    /* bootstrap via a pipe */
  1083. #define    PDX    3    /* invoked by the debugger "pdx" */
  1084. #define releq 0
  1085. #define relne 2
  1086. #define rellt 4
  1087. #define relgt 6
  1088. #define relle 8
  1089. #define relge 10
  1090. typedef enum {FALSE, TRUE} bool;
  1091.  
  1092. /*
  1093.  * interrupt and allocation routines
  1094.  */
  1095. extern long createtime;
  1096. extern char *PALLOC();
  1097. extern char *malloc();
  1098. extern long time();
  1099. extern intr();
  1100. extern memsize();
  1101. extern syserr();
  1102. extern liberr();
  1103.  
  1104. /*
  1105.  * stack routines and structures
  1106.  */
  1107. struct sze8 {
  1108.     char element[8];
  1109. };
  1110. extern short pop2();
  1111. extern long pop4();
  1112. extern double pop8();
  1113. extern struct sze8 popsze8();
  1114. extern char *pushsp();
  1115.  
  1116. /*
  1117.  * emulated pc types
  1118.  */
  1119. union progcntr {
  1120.     char *cp;
  1121.     unsigned char *ucp;
  1122.     short *sp;
  1123.     unsigned short *usp;
  1124.     long *lp;
  1125.     double *dbp;
  1126.     struct hdr *hdrp;
  1127. };
  1128.  
  1129. /*
  1130.  * THE RUNTIME DISPLAY
  1131.  *
  1132.  * The entries in the display point to the active static block marks.
  1133.  * The first entry in the display is for the global variables,
  1134.  * then the procedure or function at level one, etc.
  1135.  * Each display entry points to a stack frame as shown:
  1136.  *
  1137.  *        base of stack frame
  1138.  *          ---------------
  1139.  *          |        |
  1140.  *          | block mark  |
  1141.  *          |        |
  1142.  *          ---------------  <-- display entry "stp" points here
  1143.  *          |             |  <-- display entry "locvars" points here
  1144.  *          |   local    |
  1145.  *          |  variables  |
  1146.  *          |        |
  1147.  *          ---------------
  1148.  *          |        |
  1149.  *          |  expression |
  1150.  *          |  temporary  |
  1151.  *          |  storage    |
  1152.  *          |        |
  1153.  *          - - - - - - - -
  1154.  *
  1155.  * The information in the block mark is thus at positive offsets from
  1156.  * the display.stp pointer entries while the local variables are at negative
  1157.  * offsets from display.locvars. The block mark actually consists of
  1158.  * two parts. The first part is created at CALL and the second at entry,
  1159.  * i.e. BEGIN. Thus:
  1160.  *
  1161.  *        -------------------------
  1162.  *        |            |
  1163.  *        |  Saved lino        |
  1164.  *        |  Saved lc        |
  1165.  *        |  Saved dp        |
  1166.  *        |            |
  1167.  *        -------------------------
  1168.  *        |            |
  1169.  *        |  Saved (dp)        |
  1170.  *        |            |
  1171.  *        |  Pointer to current     |
  1172.  *        |   routine header info    |
  1173.  *        |            |
  1174.  *        |  Saved value of    |
  1175.  *        |   "curfile"        |
  1176.  *        |            |
  1177.  *        |  Empty tos value    |
  1178.  *        |            |
  1179.  *        -------------------------
  1180.  */
  1181.  
  1182. /*
  1183.  * program variables
  1184.  */
  1185. extern union display    _display;    /* runtime display */
  1186. extern struct dispsave    *_dp;        /* ptr to active frame */
  1187. extern long        _lino;        /* current line number */
  1188. extern int        _argc;        /* number of passed args */
  1189. extern char        **_argv;    /* values of passed args */
  1190. extern bool        _nodump;    /* TRUE => no post mortum dump */
  1191. extern long        _runtst;    /* TRUE => runtime tests */
  1192. extern long        _mode;        /* execl by PX, PIPE, or PIX */
  1193. extern long        _stlim;        /* statement limit */
  1194. extern long        _stcnt;        /* statement count */
  1195. extern long        _seed;        /* random number seed */
  1196. extern char        *_maxptr;    /* maximum valid pointer */
  1197. extern char        *_minptr;    /* minimum valid pointer */
  1198. extern long        *_pcpcount;    /* pointer to pxp buffer */
  1199. extern long        _cntrs;        /* number of counters */
  1200. extern long        _rtns;        /* number of routine cntrs */
  1201.  
  1202. /*
  1203.  * The file i/o routines maintain a notion of a "current file".
  1204.  * A pointer to this file structure is kept in "curfile".
  1205.  *
  1206.  * file structures
  1207.  */
  1208. struct iorechd {
  1209.     char        *fileptr;    /* ptr to file window */
  1210.     long        lcount;        /* number of lines printed */
  1211.     long        llimit;        /* maximum number of text lines */
  1212.     FILE        *fbuf;        /* FILE ptr */
  1213.     struct iorec    *fchain;    /* chain to next file */
  1214.     struct iorec    *flev;        /* ptr to associated file variable */
  1215.     char        *pfname;    /* ptr to name of file */
  1216.     short        funit;        /* file status flags */
  1217.     short        fblk;        /* index into active file table */
  1218.     long        fsize;        /* size of elements in the file */
  1219.     char        fname[NAMSIZ];    /* name of associated UNIX file */
  1220. };
  1221.  
  1222. struct iorec {
  1223.     char        *fileptr;    /* ptr to file window */
  1224.     long        lcount;        /* number of lines printed */
  1225.     long        llimit;        /* maximum number of text lines */
  1226.     FILE        *fbuf;        /* FILE ptr */
  1227.     struct iorec    *fchain;    /* chain to next file */
  1228.     struct iorec    *flev;        /* ptr to associated file variable */
  1229.     char        *pfname;    /* ptr to name of file */
  1230.     short        funit;        /* file status flags */
  1231.     short        fblk;        /* index into active file table */
  1232.     long        fsize;        /* size of elements in the file */
  1233.     char        fname[NAMSIZ];    /* name of associated UNIX file */
  1234.     char        buf[BUFSIZ];    /* I/O buffer */
  1235.     char        window[1];    /* file window element */
  1236. };
  1237.  
  1238. /*
  1239.  * unit flags
  1240.  */
  1241. #define    FDEF    0x80    /* 1 => reserved file name */
  1242. #define    FTEXT    0x40    /* 1 => text file, process EOLN */
  1243. #define    FWRITE    0x20    /* 1 => open for writing */
  1244. #define    FREAD    0x10    /* 1 => open for reading */
  1245. #define    TEMP    0x08    /* 1 => temporary file */
  1246. #define    SYNC    0x04    /* 1 => window is out of sync */
  1247. #define    EOLN    0x02    /* 1 => at end of line */
  1248. #define    EOFF    0x01    /* 1 => at end of file */
  1249.  
  1250. /*
  1251.  * file routines
  1252.  */
  1253. extern struct iorec    *GETNAME();
  1254. extern char        *MKTEMP();
  1255.  
  1256. /*
  1257.  * file record variables
  1258.  */
  1259. extern struct iorechd    _fchain;    /* head of active file chain */
  1260. extern struct iorec    *_actfile[];    /* table of active files */
  1261. extern long        _filefre;    /* last used entry in _actfile */
  1262.  
  1263. /*
  1264.  * standard files
  1265.  */
  1266. extern struct iorechd    input;
  1267. extern struct iorechd    output;
  1268. extern struct iorechd    _err;
  1269.  
  1270. /*
  1271.  * Px execution profile array
  1272.  */
  1273. #ifdef PROFILE
  1274. #define    NUMOPS 256
  1275. extern long _profcnts[NUMOPS];
  1276. #endif PROFILE
  1277. E_O_F
  1278. else
  1279.   echo "will not over write ./src/h00vars.h"
  1280. fi
  1281. chmod 644 ./src/h00vars.h
  1282. if [ `wc -c ./src/h00vars.h | awk '{printf $1}'` -ne 6978 ]
  1283. then
  1284. echo `wc -c ./src/h00vars.h | awk '{print "Got " $1 ", Expected " 6978}'`
  1285. fi
  1286. if `test ! -s ./src/textyl.pas.ah`
  1287. then
  1288. echo "writing ./src/textyl.pas.ah"
  1289. cat > ./src/textyl.pas.ah << 'E_O_F'
  1290.  
  1291.      strcopy (dvifname.str, logfilnam.str, dvifname.len);
  1292.      logfilnam.len := dvifname.len;
  1293.      rp := revindex (logfilnam, '.');
  1294.      (* add a ".tlog" extension *)
  1295.      i := rp - 1;
  1296.      logfilnam.str[i + 1] := '.';
  1297.      logfilnam.str[i + 2] := 't';
  1298.      logfilnam.str[i + 3] := 'l';
  1299.      logfilnam.str[i + 4] := 'o';
  1300.      logfilnam.str[i + 5] := 'g';
  1301.      logfilnam.len := i + 5;
  1302.  
  1303.      openlogfile;
  1304. end; 
  1305.  
  1306.  
  1307. {-----------------------------------------------------}
  1308.     function inTFM (z: integer): boolean;
  1309.     label
  1310.         9997, 9998, 9999;
  1311.     var
  1312.         k: integer;
  1313.         lh: integer;
  1314.         nw: integer;
  1315.         alpha, beta: integer; 
  1316.     begin
  1317.         readtfmword;
  1318.         lh := b2 * 256 + b3;
  1319.         readtfmword;
  1320.         font[nf].bc := b0 * 256 + b1;
  1321.         font[nf].ec := b2 * 256 + b3;
  1322.         if (font[nf].ec < font[nf].bc) then 
  1323.             font[nf].bc := font[nf].ec + 1;
  1324.         readtfmword;
  1325.         nw := b0 * 256 + b1;
  1326.         if ((nw = 0) or (nw > 256)) then 
  1327.             goto 9997;
  1328.         for k := 1 to 3 + lh do 
  1329.           begin
  1330.             if eof(tfmfile) then 
  1331.                 goto 9997;
  1332.             readtfmword;
  1333.             if (k = 4) then 
  1334.               if (b0 < 128) then 
  1335.                 tfmchecksum := ((b0 * 256 + b1) * 256 + b2) * 256 + b3
  1336.               else 
  1337.                 tfmchecksum := (((b0 - 256) * 256 + b1) * 256 + b2) * 256 + b3
  1338.           end; 
  1339.           
  1340.             for k := 0 to (font[nf].ec - font[nf].bc) do
  1341.               begin
  1342.                 readtfmword;
  1343.                 if (b0 > nw) then 
  1344.                     goto 9997;
  1345.                 font[nf].widths[k] := b0
  1346.               end; 
  1347.           alpha := 16 * z;
  1348.           beta := 16;
  1349.           while z >= TWO23 do
  1350.             begin
  1351.               z := z div 2;
  1352.               beta := beta div 2
  1353.             end;
  1354.         for k := 0 to nw - 1 do
  1355.           begin
  1356.             readtfmword;
  1357.             inwidth[k] := (((b3 * z) div 256 + b2 * z) div 256 + b1 * z) div beta;
  1358.             if b0 > 0 then 
  1359.                 if b0 < 255 then 
  1360.                     goto 9997
  1361.                 else 
  1362.                     inwidth[k] := inwidth[k] - alpha;
  1363.           end;
  1364.         if inwidth[0] <> 0 then 
  1365.             goto 9997;
  1366.         with font[nf] do
  1367.           begin
  1368.           for k := 0 to (ec - bc) do 
  1369.             if widths[k] = 0 then
  1370.               begin
  1371.               widths[k + bc] := TWO31;
  1372. {              pixelwidths[k + bc] := 0;}
  1373.               end
  1374.             else
  1375.               begin
  1376.               widths[k + bc] := inwidth[widths[k]];
  1377. {              pixelwidths[k + bc] := round(conv * widths[k]);}
  1378.               end;
  1379.            end; (* with *)
  1380.         inTFM := true;
  1381.         goto 9999;
  1382. 9997:
  1383.     complain (ERRREALBAD);
  1384.         writestrng(tfmname,true);
  1385.     writeln(logfile,'---not loaded, TFM file is bad');
  1386.           
  1387. 9998:
  1388.         inTFM := false;
  1389. 9999:
  1390.         
  1391.     end; 
  1392.  
  1393.  
  1394.  
  1395. {-----------------------------------------------------}
  1396. procedure Fastdefinefont (fn: integer);
  1397. var     p, k: integer;
  1398.         n, waste: integer;
  1399.         c, q, d: integer;
  1400.  
  1401. begin  { Fastdefinefont }
  1402.   c := Dsign4byte;
  1403.   q := Dsign4byte;
  1404.   d := Dsign4byte;
  1405.   p := Dget1byte;
  1406.   n := Dget1byte;
  1407.   for k := 1 to (p + n) do
  1408.     waste := Dget1byte;                         
  1409. end;  { Fastdefinefont }
  1410.  
  1411.  
  1412. {-----------------------------------------------------}
  1413.     procedure definefont (e: integer);
  1414.     var
  1415.         f: 0..MAXFONTS;
  1416.         p, k: integer;
  1417.         n: integer;
  1418.         c, q, d: integer;
  1419.         r: integer;
  1420.     begin
  1421.         if (nf = MAXFONTS) then 
  1422.         begin
  1423.       complain (ERRREALBAD);
  1424.           writeln(logfile,'TeXtyl capacity exceeded (max fonts=', MAXFONTS: 1, ')!');
  1425.           writeln('TeXtyl capacity exceeded (max fonts=', MAXFONTS: 1, ')!');
  1426.           jumpout
  1427.         end;
  1428.         font[nf].num := e;
  1429.         f := 0;
  1430.         while font[f].num <> e do  (* find first occurrence *)
  1431.             f := f + 1; 
  1432.         c := Dsign4byte;
  1433.         font[nf].checksum := c;
  1434.         q := Dsign4byte;
  1435.         font[nf].scaledsize := q;
  1436.         d := Dsign4byte;
  1437.         font[nf].designsize := d;
  1438.         p := Dget1byte;
  1439.         n := Dget1byte;
  1440.         font[nf].name.len := p + n;
  1441.         for k := 1 to (p + n) do
  1442.            font[nf].name.str[k] := Dget1byte;
  1443.  
  1444.         if (f = nf) then 
  1445.         begin (* f = nf *)
  1446.             for k := 1 to AREALENGTH do 
  1447.                 tfmname.str[k] := ' ';
  1448.  
  1449.               r := 0;
  1450.             
  1451.             for k := 1 to font[nf].name.len do 
  1452.               begin
  1453.                 r := r + 1;
  1454.                 tfmname.str[r] := xchr[font[nf].name.str[k]]
  1455.               end;
  1456.             tfmname.str[r + 1] := '.';
  1457.             tfmname.str[r + 2] := 't';
  1458.             tfmname.str[r + 3] := 'f';
  1459.             tfmname.str[r + 4] := 'm';
  1460.  
  1461.         tfmname.str[r + 5] := chr(32);
  1462.  
  1463.         tfmname.len := r + 4;
  1464.  
  1465.             if (not opentfmfile) then
  1466.           begin
  1467.             complain (ERRREALBAD);
  1468.                 writestrng(tfmname,true);
  1469.         writeln(logfile,'---not loaded, TFM file can''t be opened!');
  1470.         writestrng(tfmname, false);
  1471.         writeln(' cannot be opened. Aborting.');
  1472.         jumpout;
  1473.              end
  1474.             else 
  1475.               begin
  1476.                 if (q <= 0) or (q >= TWO27) then 
  1477.           begin
  1478.             complain (ERRREALBAD);
  1479.                     writestrng(tfmname,true);
  1480.                     writeln(logfile,'---not loaded, bad scale (', q: 1, ')!');
  1481.           end
  1482.                 else if (d <= 0) or (d >= TWO27) then 
  1483.           begin
  1484.             complain (ERRREALBAD);
  1485.                     writestrng(tfmname,true);
  1486.                     writeln(logfile,'---not loaded, bad design size (', d: 1, ')!');
  1487.           end
  1488.                 else
  1489.                   if inTFM(q) then
  1490.                     begin (* intfm *)
  1491.                     font[nf].space := q div 6;
  1492.                     if (c <> 0) and (tfmchecksum <> 0) and (c <> tfmchecksum) then 
  1493.                       begin
  1494.                       writeln(logfile,'Problem in fig#',pgfigurenum:0,' on page ',currpagenum:0);
  1495.                   writestrng(tfmname,true);
  1496.                       writeln(logfile,'---beware: check sums do not agree!');
  1497.                       writeln(logfile,'   (', c: 1, ' vs. ', tfmchecksum: 1, ')');
  1498.                       end;
  1499.                     d := round(100.0 * conv * q / (trueconv * d));
  1500.                     nf := nf + 1;
  1501.                     font[nf].space := 0;
  1502.                     end (* intfm *)
  1503.                  end;
  1504.             end;
  1505.     end;
  1506.  
  1507. {-----------------------------------------------------}
  1508.     function firstpar (o: OctByt): integer;
  1509.     var fpar : integer;
  1510.     begin
  1511.        case (o) of
  1512.             0, 1, 2, 3, 4, 5, 6,
  1513.             7, 8, 9, 10, 11, 12, 13,
  1514.             14, 15, 16, 17, 18, 19, 20,
  1515.             21, 22, 23, 24, 25, 26, 27,
  1516.             28, 29, 30, 31, 32, 33, 34,
  1517.             35, 36, 37, 38, 39, 40, 41,
  1518.             42, 43, 44, 45, 46, 47, 48,
  1519.             49, 50, 51, 52, 53, 54, 55,
  1520.             56, 57, 58, 59, 60, 61, 62,
  1521.             63, 64, 65, 66, 67, 68, 69,
  1522.             70, 71, 72, 73, 74, 75, 76,
  1523.             77, 78, 79, 80, 81, 82, 83,
  1524.             84, 85, 86, 87, 88, 89, 90,
  1525.             91, 92, 93, 94, 95, 96, 97,
  1526.             98, 99, 100, 101, 102, 103, 104,
  1527.             105, 106, 107, 108, 109, 110, 111,
  1528.             112, 113, 114, 115, 116, 117, 118,
  1529.             119, 120, 121, 122, 123, 124, 125,
  1530.             126, 127:
  1531.                 fpar := o - 0;
  1532.             128, 133, 235, 239, 243:
  1533.                 fpar := Dget1byte;
  1534.             129, 134, 236, 240, 244:
  1535.                 fpar := Dget2byte;
  1536.             130, 135, 237, 241, 245:
  1537.                 fpar := Dget3byte;
  1538.             143, 148, 153, 157, 162, 167:
  1539.                 fpar := Dsign1byte;
  1540.             144, 149, 154, 158, 163, 168:
  1541.                 fpar := Dsign2byte;
  1542.             145, 150, 155, 159, 164, 169:
  1543.                 fpar := Dsign3byte;
  1544.             131, 132, 136, 137, 146, 151, 156,
  1545.             160, 165, 170, 238, 242, 246:
  1546.                 fpar := Dsign4byte;
  1547.             138, 139, 140, 141, 142, 247, 248,
  1548.             249, 250, 251, 252, 253, 254, 255:
  1549.                 fpar := 0;
  1550.             147:
  1551.                 fpar := w;
  1552.             152:
  1553.                 fpar := x;
  1554.             161:
  1555.                 fpar := y;
  1556.             166:
  1557.                 fpar := z;
  1558.             171, 172, 173, 174, 175, 176, 177,
  1559.             178, 179, 180, 181, 182, 183, 184,
  1560.             185, 186, 187, 188, 189, 190, 191,
  1561.             192, 193, 194, 195, 196, 197, 198,
  1562.             199, 200, 201, 202, 203, 204, 205,
  1563.             206, 207, 208, 209, 210, 211, 212,
  1564.             213, 214, 215, 216, 217, 218, 219,
  1565.             220, 221, 222, 223, 224, 225, 226,
  1566.             227, 228, 229, 230, 231, 232, 233,
  1567.             234:
  1568.                 fpar := o - 171
  1569.         end;
  1570.         firstpar := fpar;
  1571.     end;
  1572.  
  1573. {-----------------------------------------------------}
  1574.     function specialcases (o: OctByt; p: integer): boolean;
  1575.     label
  1576.         46, 44, 30, 9998;
  1577.     var
  1578.         pure: boolean;
  1579.  
  1580.     begin
  1581.         pure := true;
  1582.         if ((o < 157) or (o > 249)) then
  1583.           begin
  1584.         complain (ERRREALBAD);
  1585.             writeln(logfile, 'undefined command ', o: 1, '!');
  1586.             goto 30;
  1587.           end;
  1588.         case (o) of 
  1589.             157, 158, 159, 160:
  1590.                 begin
  1591.                     goto 44;
  1592.                 end;
  1593.             161, 162, 163, 164, 165:
  1594.                 begin
  1595.                     y := p;
  1596.                     goto 44;
  1597.                 end;
  1598.             166, 167, 168, 169, 170:
  1599.                 begin
  1600.                     z := p;
  1601.                     goto 44;
  1602.                 end; 
  1603.             171, 172, 173, 174, 175, 176, 177,
  1604.             178, 179, 180, 181, 182, 183, 184,
  1605.             185, 186, 187, 188, 189, 190, 191,
  1606.             192, 193, 194, 195, 196, 197, 198,
  1607.             199, 200, 201, 202, 203, 204, 205,
  1608.             206, 207, 208, 209, 210, 211, 212,
  1609.             213, 214, 215, 216, 217, 218, 219,
  1610.             220, 221, 222, 223, 224, 225, 226,
  1611.             227, 228, 229, 230, 231, 232, 233,
  1612.             234:
  1613.                 begin
  1614.                     goto 46;
  1615.                 end;
  1616.             235, 236, 237, 238:
  1617.                 begin
  1618.                     goto 46;
  1619.                 end;
  1620.             243, 244, 245, 246:
  1621.                 begin
  1622.                     definefont(p);
  1623.                     goto 30;
  1624.                 end;
  1625.  
  1626.             239, 240, 241, 242:
  1627.                 begin   (* =========specials============= *)
  1628.                   mainhandlespecials (o, p);
  1629.                   goto 30;
  1630.                 end; 
  1631.             247:
  1632.                 begin
  1633.           complain (ERRREALBAD);
  1634.                   writeln(logfile,'preamble command within a page!');
  1635.                   goto 9998;
  1636.                 end;
  1637.             248, 249:
  1638.                 begin
  1639.           complain (ERRREALBAD);
  1640.                   writeln(logfile,'postamble command within a page!');
  1641.                   goto 9998;
  1642.                 end;
  1643.        (*     others:
  1644.                 begin
  1645.                   write(' ', 'undefined command ', o: 1, '!');
  1646.                   goto 30;
  1647.                 end   
  1648.     *)
  1649.         end;
  1650. 44:  (* label *)
  1651.         if (v > 0) and (p > 0) then 
  1652.             if (v > TWO31 - p) then 
  1653.             begin
  1654.                 p := TWO31 - v
  1655.             end;
  1656.         if (v < 0) and (p < 0) then 
  1657.             if ((-v) > (p + TWO31)) then 
  1658.             begin
  1659.                 p := -v - TWO31
  1660.             end;
  1661.  
  1662.         v := v + p;
  1663.  
  1664.         goto 30;
  1665. 46:  (* label *)
  1666.         font[nf].num := p;
  1667.         curfont := 0;
  1668.         while font[curfont].num <> p do 
  1669.             curfont := curfont + 1;
  1670.         goto 30 ;
  1671. 9998:
  1672.         pure := false;
  1673. 30:
  1674.         specialcases := pure;
  1675.     end; 
  1676.  
  1677.  
  1678. {-----------------------------------------------------}
  1679.     function dopage : boolean;
  1680.     label
  1681.         41, 42, 43, 30, 9998, 9999;
  1682.     var
  1683.         o: OctByt;
  1684.         p, q: integer;
  1685.  
  1686.     begin
  1687.         curfont := nf;
  1688.      s := 0;
  1689.         h := 0;
  1690.         v := 0;
  1691.         w := 0;
  1692.         x := 0;
  1693.         y := 0;
  1694.         z := 0;
  1695.       
  1696.         ourxpos := 0;
  1697.     ourypos := 0;
  1698.     ourfontnum := (-1);
  1699.         while true do 
  1700.           begin 
  1701.             o := Dget1byte;
  1702.             p := firstpar(o);
  1703.             if eof(dvifile) then begin
  1704.                 writeln(logfile, 'Bad DVI file: ', 'the file ended prematurely', '!');
  1705.                 writeln('Bad DVI file: ', 'the file ended prematurely', '!');
  1706.                 jumpout
  1707.             end; 
  1708.             if o <= 131 then 
  1709.               begin 
  1710.                 goto 41;
  1711.               end
  1712.             else
  1713.               begin
  1714.                if (o > 156) then
  1715.                  begin
  1716.                    if specialcases(o, p) then 
  1717.                       goto 30
  1718.                    else 
  1719.                       goto 9998;
  1720.                  end;
  1721.                                          
  1722.                 case (o) of
  1723.                     133, 134, 135, 136:
  1724.                         begin
  1725.                           goto 41;
  1726.                         end;
  1727.                     132, 137:
  1728.                         begin
  1729.                             goto 42
  1730.                         end;
  1731.                     138:
  1732.                         begin
  1733.                             goto 30;
  1734.                         end;
  1735.                     139:
  1736.                         begin (* BOP *)
  1737.               complain (ERRREALBAD);
  1738.                           writeln(logfile, 'bop occurred before eop');
  1739.                           goto 9998; (* Fail *)
  1740.                         end;
  1741.                     140:
  1742.                         begin (* EOP *)
  1743.                             if (s <> 0) then 
  1744.                   begin
  1745.                   complain (ERRREALBAD);
  1746.                               writeln(logfile, 'stack not empty at end of page (level ', s: 1, ')!');
  1747.                   end;
  1748.                 if (multifigure <> 0) then
  1749.                   begin
  1750.                     complain (ERRBAD);
  1751.                     writeln(logfile,'Some figure definition not closed at end of page ', currpagenum:0,'!');
  1752.                   end;
  1753.                                    
  1754.                             write (currpagenum:0,']'); 
  1755.                             write (logfile,currpagenum:0,']'); 
  1756.                 if ((currpagenum mod 10) = 0) then
  1757.                   writeln;
  1758.                             dopage := true;
  1759.                             goto 9999;
  1760.                         end;
  1761.                     141:
  1762.                         begin (* PUSH *)
  1763.                           with stack[s] do 
  1764.                             begin
  1765.                             sh := h;
  1766.                             sv := v;
  1767.                             sw := w;
  1768.                             sx := x;
  1769.                             sy := y;
  1770.                             sz := z;
  1771.                             end; (* with *)
  1772.                           s := s + 1;
  1773.                           goto 30;
  1774.                         end;
  1775.                     142:
  1776.                         begin (* POP *)
  1777.                             if s = 0 then 
  1778.                   begin
  1779.                   complain (ERRREALBAD);
  1780.                               writeln(logfile,'illegal pop at level zero!');
  1781.                   end
  1782.                             else 
  1783.                   begin
  1784.                                 s := s - 1;
  1785.                                 with stack[s] do
  1786.                                   begin
  1787.                                   h := sh;
  1788.                                   v := sv;
  1789.                                   w := sw;
  1790.                                   x := sx;
  1791.                                   y := sy;
  1792.                                   z := sz;
  1793.                                   end;
  1794.                                end;
  1795.                             goto 30;
  1796.                         end; 
  1797.                     143, 144, 145, 146:
  1798.                         begin
  1799.                             q := p;
  1800.                             goto 43
  1801.                         end;
  1802.                     147, 148, 149, 150, 151:
  1803.                         begin
  1804.                             w := p;
  1805.                             q := p;
  1806.                             goto 43
  1807.                         end;
  1808.                     152, 153, 154, 155, 156:
  1809.                         begin
  1810.                             x := p;
  1811.                             q := p;
  1812.                             goto 43
  1813.                         end; 
  1814.                 (*    others:
  1815.                         if specialcases(o, p) then 
  1816.                             goto 30
  1817.                         else 
  1818.                             goto 9998;
  1819.                                 *)                          
  1820.                 end; (* case *)
  1821.             end; (* else *)
  1822. 41:   (* finish cmd to set/put a char *)
  1823.             if p < 0 then 
  1824.                 p := 255 - (-1 - p) mod 256
  1825.             else if p >= 256 then 
  1826.                 p := p mod 256;
  1827.             if (p < font[curfont].bc) or (p > font[curfont].ec) then 
  1828.                 q := TWO31
  1829.             else 
  1830.                 q := font[curfont].widths[p];
  1831.             if (q = TWO31) then 
  1832.               begin
  1833.             complain (ERRREALBAD);
  1834.                 writeln(logfile,'Character ', p:1,' invalid in font #',curfont:0);
  1835.               end;
  1836.             if o >= 133 then 
  1837.                 goto 30;
  1838.             if q = TWO31 then 
  1839.                 q := 0;
  1840.             goto 43;
  1841.  
  1842. 42:  (* finish cmd to set/put rule *)
  1843.             q := Dsign4byte;
  1844.             if o = 137 then 
  1845.                 goto 30;
  1846.             goto 43 ;
  1847.  
  1848. 43:  (*finish cmd that sets h += q *)
  1849.             if (h > 0) and (q > 0) then 
  1850.                 if (h > (TWO31 - q)) then 
  1851.                   begin
  1852.                     q := TWO31 - h
  1853.                   end;
  1854.             if (h < 0) and (q < 0) then 
  1855.                 if ((-h) > (q + TWO31)) then 
  1856.                   begin
  1857.                     q := (-h) - TWO31
  1858.                   end;
  1859.  
  1860.             h := h + q;
  1861. 30:
  1862.         end;
  1863. 9998:
  1864.         dopage := false;
  1865. 9999:
  1866.  
  1867.     end; 
  1868.  
  1869. {-----------------------------------------------------}
  1870.     procedure skippages;
  1871.     label
  1872.         9999;
  1873.     var
  1874.         p: integer;
  1875.         k: 0..255;
  1876.         downthedrain: integer;
  1877.     begin
  1878.         while true do 
  1879.           begin
  1880.             if eof(dvifile) then 
  1881.               begin
  1882.                 writeln(logfile, 'Bad DVI file: ', 'the file ended prematurely', '!');
  1883.                 write(' ', 'Bad DVI file: ', 'the file ended prematurely', '!');
  1884.                 jumpout
  1885.               end;
  1886.             k := Dget1byte;
  1887.             p := firstpar(k);
  1888.             case (k) of
  1889.                 139:
  1890.                     begin (* BOP *)
  1891.                         newbackptr := DVIMark + TotBytesWritten - 1;
  1892.             currpagenum := Dsign4byte; (* count[0] *)
  1893.                         for k := 1 to 9 do 
  1894.                             waste := Dsign4byte; (* WAS count[k] := *)
  1895.                         downthedrain := Dsign4byte;
  1896.                         BackupInBuf (4);
  1897.                         cmdSigned (oldbackptr, 4);
  1898.                         oldbackptr := newbackptr;
  1899.                         write(' ['); 
  1900.                         write(logfile,' ['); 
  1901.                         goto 9999;
  1902.                     end;
  1903.                 132, 137: (* RULE *)
  1904.                     downthedrain := Dsign4byte;
  1905.                 243, 244, 245, 246:
  1906.                     begin
  1907.                         definefont(p);
  1908.                     end;
  1909.                 239, 240, 241, 242: (* specials *)
  1910.                     begin
  1911.                         mainhandlespecials (k, p);
  1912.                     end;
  1913.                 248:
  1914.                     begin (* POST *)
  1915.                         ourq := DVIMark + TotBytesWritten - 1;
  1916.                         inpostamble := true;
  1917.                         goto 9999
  1918.                     end;
  1919.               (*  others:
  1920.                     null
  1921.         *)
  1922.             end
  1923.         end;
  1924.     9999:
  1925.  
  1926.     end; 
  1927.  
  1928. {-----------------------------------------------------}
  1929.     procedure readpostamble;
  1930.     var
  1931.         k: integer;
  1932.         p, q, m: integer;
  1933.         indx : integer;
  1934.     begin
  1935.         if (Dsign4byte <> numerator) then 
  1936.             writeln(logfile,'Postamble',' numerator',' doesn''t match the preamble!');
  1937.         if (Dsign4byte <> denominator) then 
  1938.             writeln(logfile,'Postamble',' denominator',' doesn''t match the preamble!');
  1939.         if (Dsign4byte <> mag) then 
  1940.            begin
  1941.            writeln(logfile,'Postamble',' magnification',' doesn''t match the preamble!');
  1942.            end;
  1943.         maxv := Dsign4byte;
  1944.         maxh := Dsign4byte;
  1945.         maxs := Dget2byte;
  1946.         BackupInBuf (2);
  1947.         cmd2byte (maxs + 2); (* pretend the stack depth 
  1948.                   * does not increase by
  1949.                   * more than two
  1950.                   *)
  1951.         
  1952.         totalpages := Dget2byte;
  1953.         repeat
  1954.             k := Dget1byte;
  1955.             if (k >= 243) and (k < 247) then 
  1956.               begin
  1957.                 p := firstpar(k);
  1958.                 Fastdefinefont(p);
  1959.                 k := 138;
  1960.               end
  1961.         until k <> 138; (* NOP *)
  1962.  
  1963.        (* here, backup 1, enter all our fonts and 
  1964.         then output the 249 that we backed over *)
  1965.         BackupInBuf (1);
  1966.         for indx := 1 to MFontsDefd do
  1967.           begin
  1968.           with MFontTable[indx]^ do 
  1969.             enterfont (DVIFontNum, Cksum, DesSize,
  1970.                        DesSize, FontName );
  1971.           end; (* for *)
  1972.         for indx := 1 to VFontsDefd do
  1973.           begin
  1974.           with VFontTable[indx]^ do
  1975.             enterfont (DVIFontNum, Cksum, DesSize,
  1976.                         DesSize, FontName);
  1977.           end;  (* for *)
  1978.     for indx := 1 to LFontsDefd do
  1979.       begin
  1980.       with LFontTable[indx]^ do
  1981.         enterfont (DVIFontNum, Cksum, DesSize,
  1982.                 DesSize, FontName);    
  1983.       end;
  1984.         cmd1byte(249);  (* post post *)
  1985.  
  1986.         if (k <> 249) then 
  1987.             writeln(logfile,'byte ',k:0,' is not postpost!');
  1988.         q := Dsign4byte;
  1989.         BackupInBuf (4);
  1990.         cmd4byte (ourq);
  1991.         m := Dget1byte;
  1992.         if (m <> 2) then 
  1993.             writeln(logfile,'identification should be ', 2: 1, '!');
  1994.         m := 223;
  1995.         while (m = 223) and not eof(dvifile) do 
  1996.             m := Dget1byte;
  1997.         if not eof(dvifile) then 
  1998.     begin
  1999.             writeln(' ', 'Bad DVI file: ', 'signature in should be 223', '!');
  2000.             writeln(logfile, 'Bad DVI file: ', 'signature in should be 223', '!');
  2001.             jumpout
  2002.         end;
  2003.     end;
  2004.  
  2005.  
  2006. (* MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN *)
  2007. begin (* main *)
  2008.     initialize;
  2009.     AskandOpenFiles;  (* ask for filenames of inputdvi and outputfil *)
  2010.  
  2011.     writeln(logfile, TylVersion,' for Berkeley Unix');    
  2012.  
  2013.     write(logfile,'Reading File: ');
  2014.     writestrng(dvifname,true);     
  2015.     writeln(logfile);
  2016.  
  2017.  
  2018.     p := Dget1byte;
  2019.     if (p <> 247) then 
  2020.     begin
  2021.         write(' ', 'Bad DVI file: ', 'First byte isn''t start of preamble!', '!');
  2022.         writeln(logfile,'Bad DVI file: ', 'First byte isn''t start of preamble!', '!');
  2023.         jumpout
  2024.     end;
  2025.     p := Dget1byte;
  2026.     if (p <> 2) then 
  2027.         writeln(logfile,'identification in byte 1 should be ', 2: 1, '!');
  2028.     numerator := Dsign4byte;
  2029.     denominator := Dsign4byte;
  2030.     if (numerator <= 0) then 
  2031.     begin
  2032.         write(' ', 'Bad DVI file: ', 'numerator is ', numerator: 1, '!');
  2033.         writeln(logfile, 'Bad DVI file: ', 'numerator is ', numerator: 1, '!');    
  2034.         jumpout
  2035.     end;
  2036.     if (denominator <= 0) then 
  2037.     begin
  2038.         write(' ', 'Bad DVI file: ', 'denominator is ', denominator: 1, '!');
  2039.         writeln(logfile, 'Bad DVI file: ', 'denominator is ', denominator: 1, '!');
  2040.         jumpout
  2041.     end;
  2042.     conv := numerator / 254000.0 * (resolution / denominator);
  2043.     mag := Dsign4byte;
  2044.     if (mag <= 0) then 
  2045.     begin
  2046.         write(' ', 'Bad DVI file: ', 'magnification is ', mag: 1, '!');
  2047.         writeln(logfile, 'Bad DVI file: ', 'magnification is ', mag: 1, '!');
  2048.         jumpout
  2049.     end;
  2050.     magfactor := mag / 1000.0;
  2051.     trueconv := conv;
  2052.     conv := trueconv * magfactor;
  2053.     p := Dget1byte;     (* the 'k' of the preamble *)
  2054.     while p > 0 do 
  2055.     begin
  2056.         p := p - 1;
  2057.         waste := Dget1byte;
  2058.     end;
  2059.  
  2060.     skippages;
  2061.     if not inpostamble then 
  2062.     begin 
  2063.         while (maxpages > 0) do 
  2064.           begin (* while *)
  2065.             maxpages := maxpages - 1;
  2066.             if (not dopage) then 
  2067.               begin
  2068.                 write(' ', 'Bad DVI file: ', 'page ended unexpectedly', '!');
  2069.                 writeln(logfile, 'Bad DVI file: ', 'page ended unexpectedly', '!');
  2070.                 jumpout
  2071.               end;
  2072.         (* now we are at an EOP ---end of page *)
  2073.         (*  flushout GDVIbuffer, and reset counters *)
  2074. {         writeln('EOP: bytes used= ',GDVIBuf.TotByteLen:0);  }
  2075.             WriteDVIBuf;
  2076.             ClearDVIBuf;
  2077.             multifigure := 0;
  2078.         pgfigurenum := 0;
  2079.             FTBDs := 0;
  2080.             didnewfonts := false;
  2081.             repeat
  2082.                 k := Dget1byte;
  2083.                 if (k >= 243) and (k < 247) then  
  2084.                   begin (* fontdefs *)
  2085.                     p := firstpar(k);
  2086.                     definefont(p);
  2087.                     k := 138
  2088.                   end;
  2089.             until (k <> 138); (* nop *)
  2090.  
  2091.             if (k = 248) then 
  2092.             begin
  2093.                 inpostamble := true;
  2094.                 ourq := DVIMark + TotBytesWritten - 1;
  2095.                 goto 30
  2096.             end;
  2097.  
  2098.             if (k = 139) then  (* BOP *)
  2099.             begin
  2100.         newbackptr := DVIMark + TotBytesWritten - 1;
  2101.         currpagenum := Dsign4byte; (* Count[0] *)
  2102.         for k := 1 to 9 do 
  2103.             waste := Dsign4byte; (* WAS count[k] := *)
  2104.         waste := Dsign4byte; (* backpointer *)
  2105.         BackupInBuf (4);
  2106.         cmdSigned (oldbackptr, 4);
  2107.         oldbackptr := newbackptr;
  2108.         write(' ['); 
  2109.         write(logfile,' ['); 
  2110.           end
  2111.         else
  2112.               begin (* NOT bop?? *)
  2113.         writeln('We did not find BOP when expected');
  2114.         writeln(logfile,'We did not find BOP when expected');
  2115.                 jumpout;
  2116.               end;
  2117.  
  2118.         end; (* while *)
  2119. 30: 
  2120.     end; (* if not inpostamble *)
  2121.     if (not inpostamble) then 
  2122.     skippages;
  2123.     waste := Dsign4byte; (* ptr to the last bop in file *)
  2124.     BackupInBuf (4);
  2125.     cmdSigned (oldbackptr, 4);
  2126.     readpostamble;
  2127.     WriteDVIBuf;
  2128.  
  2129.     while ((TotBytesWritten mod 4) <> 0) do
  2130.        OutputByte(223);  (* final signatures *)
  2131.  
  2132.     writeln;
  2133.     writeln(logfile);
  2134.     write ('Output written on '); 
  2135.     writestrng(outname, false); 
  2136.     write(' (',currpagenum:0,' page');
  2137.     if (currpagenum > 1) then
  2138.       write('s');
  2139.     writeln(', ',TotBytesWritten:0,' bytes).');
  2140.  
  2141.     write (logfile,'Output written on ');
  2142.     writestrng(outname, true); 
  2143.     write(logfile,' (',currpagenum:0,' page');
  2144.     if (currpagenum > 1) then
  2145.       write(logfile,'s');
  2146.     writeln(logfile,', ',TotBytesWritten:0,' bytes).');
  2147.  
  2148.     write ('Log written on ');
  2149.     writestrng(logfilnam, false); writeln;
  2150.     write (logfile,'Log written on '); 
  2151.     writestrng(logfilnam, true); writeln (logfile);
  2152.     writeln;
  2153.     writeln(logfile);
  2154. 666:
  2155.     if (ErrorOccurred) then
  2156.       begin
  2157.         writeln;
  2158.         writeln('Some error(s) occurred. Please check Logfile for details');
  2159.         writeln('Assume that the outputfile is incorrect');
  2160.       end;
  2161. end. 
  2162.  
  2163. E_O_F
  2164. else
  2165.   echo "will not over write ./src/textyl.pas.ah"
  2166. fi
  2167. chmod 644 ./src/textyl.pas.ah
  2168. if [ `wc -c ./src/textyl.pas.ah | awk '{printf $1}'` -ne 26804 ]
  2169. then
  2170. echo `wc -c ./src/textyl.pas.ah | awk '{print "Got " $1 ", Expected " 26804}'`
  2171. fi
  2172. echo "Finished archive 4 of 9"
  2173. exit
  2174.